package com.aaa.fpa.controller;

import com.aaa.fpa.service.UsersService;
import com.aaa.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private UsersService usersService;

    /**
     * 用户注册
     * @param users
     * @return
     */
/*    @RequestMapping("/saveusers")
    public String insert(Users users) {
        System.out.println("注册");
        // 调用注入的 usersService 调用 insertUsers 方法
        usersService.saveusers(users);
        return "success";
    }*/

    /**
     * 用户登录
     * @param users
     * @return
     */
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login( Model model ,HttpServletRequest request,  Users users) {

        // 调用注入的 usersService 调用 login 方法

        if(usersService.login(users)){
            request.getSession().setAttribute("users", users);
            return "/subject.jsp";
        }else{
            model.addAttribute("msg","用户名或密码错误");
            return  "/index.jsp";
        }
    }



}
